import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

try {
	function isPromise(obj) {
		return (
			!!obj &&
			(typeof obj === "object" || typeof obj === "function") &&
			typeof obj.then === "function"
		);
	}

	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) {}

const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
// 导入vant ui样式文件
import 'vant/lib/index.css'
// 引入vant组件
import {
	Button,
	CellGroup,
	Dialog,
	Field,
	Form,
	Icon,
	Lazyload,
	Search,
	Skeleton,
	SkeletonAvatar,
	SkeletonImage,
	SkeletonParagraph,
	SkeletonTitle,
	Space,
	Swipe,
	SwipeItem,
	Toast
} from 'vant'

export function createApp() {
	const app = createSSRApp(App)
	// 挂载vant ui
	app.use(Button).use(Search).use(Toast).use(Space).use(Swipe).use(SwipeItem).use(Lazyload, {
		lazyComponent: true
	})
	app.use(Skeleton);
	app.use(SkeletonTitle);
	app.use(SkeletonImage);
	app.use(SkeletonAvatar);
	app.use(SkeletonParagraph);
	app.use(Form);
	app.use(Field);
	app.use(CellGroup);
	app.use(Dialog);
	app.use(Icon)

	return {
		app
	}
}


// #endif
